import Vue from 'vue'
import Vuex from 'vuex'
import { routeRegistered } from '../config'
Vue.use(Vuex)
/*
@description 描述
@author ZhaoliangJi
@param {String} current 左侧标识符
@param {String} routerName 路由出口
@param {Object} TsinghuaId 全局锚点id
@param {String} currentIndex 右侧选中项

@time2021-11-15 11:29:44
*/

export default new Vuex.Store({
  state: {
    current: "tsinghua-Ui",
    routerName: '',
    TsinghuaId: {},
    currentIndex: 'ds-cloud-0',
  },
  mutations: {
    ROUTER_NAME(state, link) {
      state.routerName = routeRegistered[link == 'HomeApp' ? 'Assembly' : link]
    },
    TSINGHUA_ID(state, id) {
      state.TsinghuaId = id
    },
    CURRENT(state, index) {
      state.current = index
    },
    CURRENT_INDEX(state, index) {
      state.currentIndex = index
    }
  },
  actions: {
    //h2标签 => 
    /*
    @description 描述:全局锚点铺垫 => Global anchor jump paving
    @author ZhaoliangJi
    @param {Object} object 参数传递
    @time2021-11-18 10:19:11
    */
    addElementId({ commit }) {
      const ELMENTS_H2 = document.getElementsByTagName("h2");
      let object = new Object();
      for (let i = 0; i < ELMENTS_H2.length; i++) {
        ELMENTS_H2[i].setAttribute("id", "ds-cloud-" + i);
        object[ELMENTS_H2[i].id] = ELMENTS_H2[i].innerHTML;
      }
      commit("TSINGHUA_ID", object);
    },
    /*
    @description 描述:全局锚点跳转 => Global anchor jump 
    @author ZhaoliangJi
    @param {string} idVal 唯一id
    @time2021-11-18 10:18:09
    */
    AnchorpointSearch({ }, idVal) {
      document.getElementById(idVal).scrollIntoView(true);
    },
  },

  modules: {
  }
})
